#include "settings.h"
#include "ui_settings.h"
#include "mainwindow.h"
#include "audiooutputer.h"
#include <irrKlang/irrKlang.h>
#include "savemanager.h"

using namespace irrklang;
double volume = 50.0;
irrklang::ISoundEngine* engine2;

Settings::Settings(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::Settings)
{
    engine2 = irrklang::createIrrKlangDevice();
    ui->setupUi(this);
    ui->horizontalSlider->setValue(int(SaveManager::GetInstance()->GetVolume()));
}

Settings::~Settings()
{
    engine2->drop();
    delete ui;
}

void Settings::on_horizontalSlider_sliderMoved(int position)
{
    volume = double(position);
}

void Settings::updateSlider(){
      ui->horizontalSlider->setValue(int(SaveManager::GetInstance()->GetVolume()));
}

void Settings::on_buttonBox_accepted()
{
    QString num = QString::number(volume);
    AudioOutputer::GetInstance()->SetVolume(volume);
    SaveManager::GetInstance()->ClearConfigs();
    SaveManager::GetInstance()->AddConfigs(num);
    SaveManager::GetInstance()->SaveConfigs( QCoreApplication::applicationDirPath() +"/settings.cfg");


}

void Settings::on_horizontalSlider_sliderReleased()
{
    engine2->setSoundVolume(volume/100);
    engine2->play2D("wav/test.wav");
}
